package org.itboys.mobile.service.mongo.weixin;


import org.itboys.commons.utils.tools.ListUtil;
import org.itboys.mobile.common.SundayCommonConstants;
import org.itboys.mobile.entity.mongo.SundayMember;
import org.itboys.mobile.entity.mongo.project.ZhongBaoProjectEmployee;
import org.itboys.mobile.entity.mongo.project.ZhongBaoProjectImage;
import org.itboys.mobile.service.mongo.web.SundayMemberService;
import org.itboys.mongodb.core.MongoDataSource;
import org.itboys.mongodb.service.BaseMongoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sun.security.provider.Sun;

import javax.annotation.Resource;
import java.util.*;

/**
 * 作者：jiangxiong
 * 日期：2017年5月8日
 * 联系方式 ：empty90911@126.com
 * 描述：众包_微信_项目_图片_service
 */
@Service
public class ZhongBaoWeiXinProjectEmployeeService extends BaseMongoService<ZhongBaoProjectEmployee> {

    @Autowired
    private SundayWeiXinMemberService memberService;

    @Resource(name = "mobileDs")
    private MongoDataSource mobileDataSource;
    @Override
    protected MongoDataSource getMongoDataSource() {
        return mobileDataSource;
    }

    @Override
    protected Class<ZhongBaoProjectEmployee> getEntityClass() {
        return ZhongBaoProjectEmployee.class;
    }


    /**
     * 保持项目员工
     * @param projectId
     * @param employeeIds
     */
    public  void saveEmployees(Long projectId,List<Long> employeeIds){
        if(ListUtil.isNull(employeeIds)){
            return;
        }
        Map<String,Object> param = new HashMap<String,Object>();
        //删除原有的项目员工


        param.put("id in",employeeIds);
        List<SundayMember> employees =memberService.list(param);
        List<ZhongBaoProjectEmployee> projectEmployees=new ArrayList<ZhongBaoProjectEmployee>();
        for(SundayMember employee:employees){
            projectEmployees.add(new ZhongBaoProjectEmployee(projectId,employee.getId(), employee.getNickName(), employee.getMobile(), employee.getImage()));
        }

        super.batchSaveWithoutLogin(projectEmployees);

    }






}
